home *** CD-ROM | disk | FTP | other *** search
/ Aminet 37 / Aminet 37 (2000)(Schatztruhe)[!][Jun 2000].iso / Aminet / dev / lang / sofa.lha / sofa / smalleiffel / lib_se / e_old.e < prev    next >
Text File  |  2000-03-25  |  8KB  |  316 lines

  1. --          This file is part of SmallEiffel The GNU Eiffel Compiler.
  2. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  3. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr
  4. --                       http://SmallEiffel.loria.fr
  5. -- SmallEiffel is  free  software;  you can  redistribute it and/or modify it
  6. -- under the terms of the GNU General Public License as published by the Free
  7. -- Software  Foundation;  either  version  2, or (at your option)  any  later
  8. -- version. SmallEiffel is distributed in the hope that it will be useful,but
  9. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. -- or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU General Public License
  11. -- for  more  details.  You  should  have  received a copy of the GNU General
  12. -- Public  License  along  with  SmallEiffel;  see the file COPYING.  If not,
  13. -- write to the  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. -- Boston, MA 02111-1307, USA.
  15. --
  16. class E_OLD
  17.    --
  18.    -- To store instruction "old ..." usable in an ensure clause.
  19.    --
  20.  
  21. inherit EXPRESSION;
  22.  
  23. creation make
  24.  
  25. feature
  26.  
  27.    expression: EXPRESSION;
  28.  
  29.    is_current: BOOLEAN is false;
  30.  
  31.    is_writable: BOOLEAN is false;
  32.  
  33.    is_static: BOOLEAN is false;
  34.  
  35.    is_pre_computable: BOOLEAN is false;
  36.  
  37.    is_manifest_string: BOOLEAN is false;
  38.  
  39.    is_manifest_array: BOOLEAN is false;
  40.  
  41.    is_result: BOOLEAN is false;
  42.  
  43.    is_void: BOOLEAN is false;
  44.  
  45.    can_be_dropped: BOOLEAN is false;
  46.  
  47.    c_simple: BOOLEAN is false;
  48.  
  49.    isa_dca_inline_argument: INTEGER is 0;
  50.  
  51.    static_result_base_class: BASE_CLASS is
  52.       do
  53.          Result := expression.static_result_base_class;
  54.       end;
  55.  
  56.    static_value: INTEGER is
  57.       do
  58.       end;
  59.  
  60.    dca_inline_argument(formal_arg_type: TYPE) is
  61.       do
  62.       end;
  63.  
  64.    result_type: TYPE is
  65.       do
  66.          Result := expression.result_type;
  67.       end;
  68.  
  69.    assertion_check(tag: CHARACTER) is
  70.       do
  71.          if vaol_check_memory.item = Void then
  72.             vaol_check_memory.set_item(Current);
  73.          else
  74.             eh.add_position(vaol_check_memory.item.start_position);
  75.             eh.append("Must not use old inside some old %
  76.                        %expression (VAOL.2).");
  77.             eh.print_as_fatal_error;
  78.          end;
  79.          expression.assertion_check(tag);
  80.          vaol_check_memory.clear;
  81.       end;
  82.  
  83.    afd_check is
  84.       do
  85.          expression.afd_check;
  86.       end;
  87.  
  88.    to_runnable(ct: TYPE): like Current is
  89.       local
  90.          exp: like expression;
  91.       do
  92.          if current_type = Void then
  93.             current_type := ct;
  94.             exp := expression.to_runnable(ct);
  95.             if exp = Void then
  96.                error(start_position,"Bad old expression.");
  97.             else
  98.                expression := exp;
  99.             end;
  100.             Result := Current;
  101.          else
  102.             !!Result.make(expression);
  103.             Result := Result.to_runnable(ct);
  104.          end;
  105.       end;
  106.  
  107.    stupid_switch(r: ARRAY[RUN_CLASS]): BOOLEAN is
  108.       do
  109.          Result := true;
  110.       end;
  111.  
  112.    start_position: POSITION is
  113.       do
  114.          Result := expression.start_position;
  115.       end;
  116.  
  117.    pretty_print is
  118.       do
  119.          fmt.put_string("old ");
  120.          fmt.level_incr;
  121.          expression.pretty_print;
  122.          fmt.level_decr;
  123.       end;
  124.  
  125.    print_as_target is
  126.       do
  127.          fmt.put_character('(');
  128.          pretty_print;
  129.          fmt.put_character(')');
  130.          fmt.put_character('.');
  131.       end;
  132.  
  133.    bracketed_pretty_print is
  134.       do
  135.          fmt.put_character('(');
  136.          pretty_print;
  137.          fmt.put_character(')');
  138.       end;
  139.  
  140.    short is
  141.       do
  142.          short_print.hook_or("old","old ");
  143.          expression.short;
  144.       end;
  145.  
  146.    short_target is
  147.       do
  148.          bracketed_short;
  149.          short_print.a_dot;
  150.       end;
  151.  
  152.    precedence: INTEGER is
  153.       do
  154.          Result := 11;
  155.       end;
  156.  
  157.    mapping_c_target(target_type: TYPE) is
  158.       do
  159.          compile_to_c;
  160.       end;
  161.  
  162.    mapping_c_arg(formal_arg_type: TYPE) is
  163.       do
  164.          compile_to_c;
  165.       end;
  166.  
  167.    c_declare_for_old is
  168.       local
  169.          t: TYPE;
  170.          name: STRING;
  171.          p: POSITION;
  172.       do
  173.          name := local_c_name;
  174.          t := result_type.run_type;
  175.          tmp_string.clear;
  176.          t.c_type_for_argument_in(tmp_string);
  177.          tmp_string.extend(' ');
  178.          tmp_string.append(name);
  179.          tmp_string.extend('=');
  180.          t.c_initialize_in(tmp_string);
  181.          tmp_string.append(fz_00);
  182.          cpp.put_string(tmp_string);
  183.          if run_control.no_check then
  184.             c_frame_descriptor_locals.append("(void**)&");
  185.             c_frame_descriptor_locals.append(name);
  186.             c_frame_descriptor_locals.extend(',');
  187.             c_frame_descriptor_local_count.increment;
  188.             p := start_position;
  189.             c_frame_descriptor_format.append("old l");
  190.             p.line.append_in(c_frame_descriptor_format);
  191.             c_frame_descriptor_format.extend('c');
  192.             p.column.append_in(c_frame_descriptor_format);
  193.             c_frame_descriptor_format.append(p.base_class_name.to_string);
  194.             t.c_frame_descriptor;
  195.          end;
  196.       end;
  197.  
  198.    compile_to_c_old is
  199.       local
  200.          t: TYPE;
  201.       do
  202.          t := result_type.run_type;
  203.          tmp_string.copy(local_c_name);
  204.          tmp_string.extend('=');
  205.          cpp.put_string(tmp_string);
  206.          expression.mapping_c_arg(t);
  207.          cpp.put_string(fz_00);
  208.       end;
  209.  
  210.    collect_c_tmp is
  211.       do
  212.       end;
  213.  
  214.    compile_to_c is
  215.       do
  216.          cpp.put_string(local_c_name);
  217.       end;
  218.  
  219.    compile_to_jvm_old is
  220.       local
  221.          e: like expression;
  222.          rt: TYPE;
  223.       do
  224.          e := expression;
  225.          rt := e.result_type.run_type;
  226.          id := code_attribute.extra_local(rt);
  227.          e.compile_to_jvm;
  228.          rt.jvm_write_local(id);
  229.       end;
  230.  
  231.    compile_to_jvm is
  232.       do
  233.          expression.result_type.jvm_push_local(id);
  234.       end;
  235.  
  236.    compile_target_to_jvm is
  237.       do
  238.          standard_compile_target_to_jvm;
  239.       end;
  240.  
  241.    jvm_branch_if_false: INTEGER is
  242.       do
  243.          Result := jvm_standard_branch_if_false;
  244.       end;
  245.  
  246.    jvm_branch_if_true: INTEGER is
  247.       do
  248.          Result := jvm_standard_branch_if_true;
  249.       end;
  250.  
  251.    compile_to_jvm_into(dest: TYPE): INTEGER is
  252.       do
  253.          Result := standard_compile_to_jvm_into(dest);
  254.       end;
  255.  
  256.    jvm_assign is
  257.       do
  258.       end;
  259.  
  260.    use_current: BOOLEAN is
  261.       do
  262.          Result := expression.use_current;
  263.       end;
  264.  
  265. feature {NONE}
  266.  
  267.    current_type: TYPE;
  268.  
  269.    local_c_name_memory: STRING;
  270.          -- The C name for the local variable.
  271.  
  272.    id: INTEGER;
  273.          -- Used in Java byte code to gives a number to the
  274.          -- the extra local variable.
  275.  
  276.    make(exp: like expression) is
  277.       require
  278.          exp /= Void
  279.       do
  280.          expression := exp;
  281.       ensure
  282.          expression = exp;
  283.       end;
  284.  
  285.    local_c_name: STRING is
  286.       do
  287.          if local_c_name_memory = Void then
  288.             tmp_string.clear;
  289.             tmp_string.extend('o');
  290.             start_position.base_class.id.append_in(tmp_string);
  291.             tmp_string.extend('_');
  292.             start_position.line.append_in(tmp_string);
  293.             tmp_string.extend('_');
  294.             start_position.column.append_in(tmp_string);
  295.             local_c_name_memory := tmp_string.twin;
  296.          end;
  297.          Result := local_c_name_memory;
  298.       end;
  299.  
  300.    tmp_string: STRING is
  301.       once
  302.          !!Result.make(12);
  303.       end;
  304.  
  305.    vaol_check_memory: MEMO[E_OLD] is
  306.       once
  307.          !!Result;
  308.       end;
  309.  
  310. invariant
  311.  
  312.    expression /= Void;
  313.  
  314. end -- E_OLD
  315.  
  316.